<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>xxx</title>
    <script type="text/javascript" src="//cdn.bootcss.com/phaser/2.4.3/phaser.min.js"></script>
</head>
<body>
<div id="stage"></div>
<script type="text/javascript">
    var isGen = true;
    var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'stage', {create: create, render: render});
    function create() {
        game.stage.backgroundColor = '#6688ee';
        game.time.events.loop(game.rnd.integerInRange(50, 1000), updateCounter, this);
        game.input.onDown.add(click, this);
    }

    function click() {
        if (!isGen) {
            isGen = true;
        }
        //console.log("--");
    }
    function updateCounter() {
        if (isGen) {
            var r = game.rnd.integerInRange(0, 255);
            var g = game.rnd.integerInRange(0, 255);
            var b = game.rnd.integerInRange(0, 255);
            console.log(r + "," + g + "," + b);
            game.stage.backgroundColor = "rgb(" + r + "," + g + "," + b + ")";
            isGen = false;
        }

    }


    function render() {

        //game.debug.text("Queued events: " + game.time.events.length + ' - click to remove', 32, 32);

    }
</script>
</body>
</html>